<template>
  <view>
    <!-- 搜索框 -->
    <YgSearch />

    <!-- 轮播图 -->
    <u-swiper
      :list="swiperList"
      height="340"
      img-mode="aspectFill"
      border-radius="0"
    ></u-swiper>

    <!-- 分类 -->
    <view class="cateWrap">
      <u-image
        width="128rpx"
        height="140rpx"
        v-for="item in categoryList"
        :key="item.name"
        :src="item.image_src"
      ></u-image>
    </view>

    <!-- 楼层 -->
    <view class="floorList">
      <FloorBox
        v-for="item in floorList"
        :key="item.floor_title.name"
        :item="item"
      />
    </view>
  </view>
</template>

<script>
  import FloorBox from "./components/floor-box.vue";
  export default {
    components: {
      FloorBox,
    },
    data() {
      return {
        swiperList: [],
        categoryList: [],
        floorList: [],
      };
    },
    onLoad() {
      // 轮播图
      this.getSwiper()
      // 导航
      this.getCategory()
      // 楼层
      this.getFloor()
    },
    methods: {
      async getSwiper() {
        const { message } = await this.$u.get("/home/swiperdata");
        this.swiperList = message.map((item) => item.image_src);
        // console.log('封装好的请求数据',message);
        // const [swiperErr, swiperRes] = await uni.request({
        //   url: "https://api-hmugo-web.itheima.net/api/public/v1/home/swiperdata",
        // });
        // // console.log(res.data.message);
        // this.swiperList = swiperRes.data.message.map((item) => item.image_src);
      },
      async getCategory() {
        const { message } = await this.$u.get("/home/catitems");
        this.categoryList = message;
        // const [cateErr, cateRes] = await uni.request({
        //   url: "https://api-hmugo-web.itheima.net/api/public/v1/home/catitems",
        // });
        // this.categoryList = cateRes.data.message;
        // console.log(this.categoryList);
      },
      async getFloor() {
        const { message } = await this.$u.get("/home/floordata");
        this.floorList = message;
        // const [floorErr, floorRes] = await uni.request({
        // 	url: 'https://api-hmugo-web.itheima.net/api/public/v1/home/floordata'
        // })
        // // console.log(floorRes.data.message);
        // this.floorList = floorRes.data.message
      },
    },
  };
</script>

<style lang="scss" scoped>
  .cateWrap {
    display: flex;
    justify-content: space-around;
    margin: 12rpx 0;
  }
</style>